package araxy.blog.security.shiro;

import araxy.blog.utils.JsonUtil;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class MyAuthorizationFilter extends FormAuthenticationFilter {
    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
        Map<String,Object> map = new HashMap<>();
        map.put("flg",false);
        map.put("msg","无权访问");
        PrintWriter printWriter = response.getWriter();
        printWriter.print(JsonUtil.ObjectToJsonString(map));
        printWriter.flush();
        printWriter.close();
        return false;
    }
}
